# 用于计算平均工资
from Apps.Data.models import JobModel, JobCal

job_list = JobModel.objects.all()

ErrorList = []
for job in job_list:
    salary = job.salary_desc

    res = 0
    if salary.find('薪') != -1:
        prefix = salary.split('·')[0]
        low = prefix.split('-')[0]
        high = prefix.split('-')[1][:-1]

        subfix = salary.split('·')[1][:-1]
        # print(low, high, subfix)

        res = (float(low) + float(high)) / 2 * 1000 * int(subfix) / 12

    else:
        low = salary.split('-')[0]
        high = salary.split('-')[1][:-1]

        # print(low, high)
        try:
            res = (float(low) + float(high)) / 2 * 1000
        except Exception as e :
            ErrorList.append(job.id)   # 将一些异常   500-3500元/月 这样的添加到List中处理
            print(salary)
            continue

    print(f"Res: {res}")
    JobCal.objects.create(job=job,average_salary=res)

print(ErrorList)